package cn.zwx.business.order.service;

import cn.zwx.business.order.annotation.ZwxRemoteService;
import cn.zwx.business.order.api.OrderService;
import cn.zwx.business.order.api.vo.OrderInfoVO;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ThreadLocalRandom;

/**
 * @author zhangwenxue
 */
@Component
@ZwxRemoteService
public class OrderServiceImpl implements OrderService {

    @Override
    public OrderInfoVO getOrderInfoById(Long orderId) {
        OrderInfoVO orderInfoVO = new OrderInfoVO();
        orderInfoVO.setOrderId(orderId);
        orderInfoVO.setProduct("HUAWEI P40 8C16G 256G");
        int nextInt = ThreadLocalRandom.current().nextInt(1, 10);
        orderInfoVO.setNum(nextInt);
        orderInfoVO.setProductPrice(4000.0);
        orderInfoVO.setOrderAmount(new BigDecimal("4000.0").multiply(new BigDecimal(nextInt)).doubleValue());
        return orderInfoVO;
    }

    @Override
    public List<OrderInfoVO> getOrderList() {
        List<OrderInfoVO> list  = new ArrayList<>(8);
        ThreadLocalRandom current = ThreadLocalRandom.current();
        int num = 4;
        for (int i = 0; i < num; i++) {
            Long nextInt = current.nextLong(20, 100);
            list.add(getOrderInfoById(nextInt));
        }
        return list;
    }
}
